<?php
include_once("include/config.php");
session_start();
?>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<link rel="stylesheet" href="style/style.css" />
	
	<script type="text/javascript" src="js/jquery-1.2.3.min.js"></script>
	<script type="text/javascript" src="js/jquery-1.7.1.min.js"></script>
	<script type="text/javascript" src="js/jquery-ui-1.8.18.custom.js"></script>
	<script type="text/javascript" src="js/jquery.js"></script>
	
	<title>Accueil Live IT</title>
</head>

<body>

<!--------------------------------- HEADER ---------------------------------->

	<?php
		include("include/header.php");
	?>


<!------------------------------- NAVIGATION -------------------------------->
	
	<?php
		include("include/nav.php");
	?>
		
<!--------------------------------- SECTION --------------------------------->
	
	<section>
		<article>
			<div id="ssarticle">
<?php 
if(isset($_GET["artistname"]))
{
  $artist = ArtistQuery::create()
    ->findOneByNom($_GET["artistname"]);
  if(isset($artist))
  {
    echo "<h1>".$artist->getNom()."</h1>\n";
    if($artist->getImgUrl() != "")
    {
      echo "<img src=\"".$artist->getImgUrl().
            "\" style=\"float:left;\" height=\"200\" width=\"220\">";
    }
    echo $artist->getInfo();
    
  } else {
    echo "<div class=\"error_box\">Artist inexistant :P</div>\n";
  }  
  
} else {

  echo "<h1> Artist List </h1>\n";
  
  $count = ArtistQuery::create()->count();
  
  $artists = ArtistQuery::create()
    ->orderByNom()
 //   ->limit(20)
    ->find();
  echo "<ul id=\"artist-list\">\n";
  foreach($artists as $artist)
  {
    echo "<li><a href=\"artist.php?artistname=".$artist->getNom()."\">".$artist->getNom()."</a></li>\n";
  }
  echo "</ul>\n";
}
?>
			</div>
		</article>
		<aside>
			<div id="ssaside">
			<?php if(isset($_GET["artistname"])) {?>
			  <h1> Musiques </h1>
			  <ul>
			  <?php 
			    $artistMusiques = ArtistMusiqueQuery::create()
			      ->filterByArtistId($artist->getId())
			      ->find();
			    $musiquesID = array();
			    //var_dump($artistMusiques);
			    foreach($artistMusiques as $am)
			    {
			      //var_dump($am);
			      $musiquesID[] = $am->getMusiqueId();
			    }
			    $musiques = MusiqueQuery::create()
			      ->findPKs($musiquesID);
			    foreach($musiques as $musique)
			    {
			      echo "<li><a href=\"achat.php?musique=".$musique->getId()."\">".$musique->getTitle()."</a></li>\n";
			    }
			  ?>
			  </ul>
			</div>
			<?php } ?>
		</aside>
	</section>
	
<!--------------------------------- FOOTER ---------------------------------->	

	<?php
		include("include/footer.php");
	?>
	
	
<!--------------------------------------------------------------------------->

</body>
</html>
